/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dbconnector;



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
//import java.sql.ResultSet;
import java.sql.Statement;

public class DBDriver
{
  private static Connection con;
  private static Statement st;
  private static PreparedStatement pst;
  //private static ResultSet rs;

  static
  {
    try
    {
      Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception e) {    }
  }

  public Connection getCon()
    throws Exception
  {
    if ((con == null) || (con.isClosed()))
      con = DriverManager.getConnection("jdbc:mysql://localhost:3306/olcp", "root", "root");
    else return con;
    return con;
  }

  public static Statement getConnection(String st1)
    throws Exception
  {
    con = new DBDriver().getCon();
    if (st1.equals("READ")) {
      st = con.createStatement();
    }
    else
      st = con.createStatement(1005, 1008);
    return st;
  }

  public static PreparedStatement getPrepare(String st) throws Exception
  {
    con = new DBDriver().getCon();
    pst = con.prepareStatement(st);
    return pst;
  }
}